package com.lqs.dataservice.Service;

import com.lqs.dataservice.constants.MessageConstants;
import com.lqs.dataservice.dao.HelpsDao;
import com.lqs.dataservice.entity.Helps;
import com.nip.db.mongodb.utils.tips.Response;
import com.nip.db.mongodb.utils.tips.ResponseCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HelpsService {
    @Autowired
    HelpsDao helpsDao;


    public List<Helps> findAllHelps() {
        return helpsDao.findAll();
    }

    public Helps findHelpsById(String id) {
        return helpsDao.findById(id).orElse(null);
    }

    public Response saveHelps(Helps entity) {
        try {
            helpsDao.save(entity);
            return new Response(ResponseCode.CODE_200, MessageConstants.SUCCESS);
        } catch (Exception e) {
            return new Response(ResponseCode.CODE_202, e.getMessage());
        }
    }

    public Response deleteHelpsById(String id) {
        try {
            helpsDao.deleteById(id);
            return new Response(ResponseCode.CODE_200, MessageConstants.SUCCESS);
        } catch (Exception e) {
            return new Response(ResponseCode.CODE_202, e.getMessage());
        }
    }



}
